package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.mapper.DtsPermissionMapper;
import com.qf.pojo.DtsPermission;
import com.qf.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author 邢式瑞
 * @version 1.0
 * @project E-commercebackGroundManagementSystem
 * @date 2022/9/20 21:55
 */
@Service
public class PermissionServiceImpl  implements PermissionService {
    @Autowired
    private DtsPermissionMapper permissionMapper;

    /**
     * 根据多个角色id查询权限字符串集合
     * @param roleIds
     * @return
     */
    @Override
    public Set<String> queryByRoleIds(Integer[] roleIds) {
        Set<String> permissions = new HashSet<String>();

        //判断是否有角色参数
        if (roleIds == null || roleIds.length == 0) {
            return permissions;
        }

        //查询数据库
        QueryWrapper<DtsPermission> wapper = new QueryWrapper<>();
        wapper.in("role_id", Arrays.asList(roleIds));
        wapper.eq("deleted", false);
        List<DtsPermission> permissionList = permissionMapper.selectList(wapper);

        for (DtsPermission permission : permissionList) {
            permissions.add(permission.getPermission());
        }

        return permissions;
    }
}
